#include <iostream>
#include <memory>

class Handler {
protected:
    std::shared_ptr<Handler> nextHandler;

public:
    void setNext(std::shared_ptr<Handler> handler) {
        nextHandler = handler;
    }

    virtual void handleRequest(const std::string& request) {
        if (nextHandler) {
            nextHandler->handleRequest(request);
        }
    }

    virtual ~Handler() {}
};
class CustomerServiceHandler : public Handler {
public:
    void handleRequest(const std::string& request) override {
        if (request == "General Inquiry") {
            std::cout << "Customer Service Handling '" << request << "'\n";
        } else {
            Handler::handleRequest(request);
        }
    }
};
class FinanceHandler : public Handler {
public:
    void handleRequest(const std::string& request) override {
        if (request == "Billing Issue") {
            std::cout << "Finance Handling '" << request << "'\n";
        } else {
            Handler::handleRequest(request);
        }
    }
};
class LogisticsHandler : public Handler {
public:
    void handleRequest(const std::string& request) override {
        if (request == "Order Status") {
            std::cout << "Logistics Handling '" << request << "'\n";
        } else {
            Handler::handleRequest(request);
        }
    }
};
int main() {
    auto customerService = std::make_shared<CustomerServiceHandler>();
    auto finance = std::make_shared<FinanceHandler>();
    auto logistics = std::make_shared<LogisticsHandler>();
// 构建派生类的nextHandler ，形成顺序调用
    customerService->setNext(finance);
    finance->setNext(logistics);

    // 模拟请求
    customerService->handleRequest("General Inquiry");
    customerService->handleRequest("Billing Issue");
    customerService->handleRequest("Order Status");

    return 0;
}